package CTRLayer;
import java.util.HashMap;
import ModelLayer.*;

/**
 * Controller class for products
 * 
 * @author (AF, RA, KP, RL) 
 * @version (2012.06.05)
 */
public class ProductCTR
{
    private ProductCollection products;

    /**
     * Constructor for objects of class ProductCTR
     */
    public ProductCTR()
    {
        products = ProductCollection.getInstance();
    }

    
    /**
     * adds a NonCompositeProduct to container of product
     * 
     * @param productName name of Product
     * @param productDescription description of Product
     * @param barcode barcode of Product
     * @param price price of Product
     * @param retailPrice retailPrice of Product
     * @param maxCapacity maxCapacity of Product
     * @param minCapacity minCapacity of Product
     * @param location location of Product
     * @param quantity quantity of Product
     * 
     * @return none
     */
    public void addNonCompositeProduct(String productName, String productDescription, int barcode, 
                                       double price, double retailPrice, 
                                       int maxCapacity, int minCapacity, String location, int quantity)
    {

        NonCompositeProduct nonCompositeProduct = new NonCompositeProduct(productName, productDescription, 
                                                  barcode, price, retailPrice, quantity, maxCapacity, 
                                                  minCapacity, location);
        Integer bar = (Integer) barcode;
        products.addProduct(bar, nonCompositeProduct);
    }
    
    /**
     * creates an instance of a CompositeProduct
     * 
     * @param productName name of Compostite Product Instance
     * @param productDescription description of Compostite Product Instance
     * @param barcode barcode of Compostite Product Instance
     * @param price price of Compostite Product Instance
     * @param retailPrice retailPrice of Compostite Product Instance
     * @param quantity quantity of Compostite Product Instance
     * 
     * @return none
     */
    public void createCompositeProduct(String productName, String productDescription, int barcode, 
                                       double price, double retailPrice, int quantity)
    {

        CompositeProduct compositeProduct = new CompositeProduct(productName, productDescription, 
                                                  barcode, price, retailPrice, quantity);
        Integer bar = (Integer) barcode;
        products.addProduct(bar, compositeProduct);
    }
    
    /**
     * adds a PartList to a Product
     * 
     * @param barcode barcode of Product to add PartList to
     * @param subBarcode subBarcode of Product to add PartList to
     * @param quantity quantity of Product to add PartList to
     * 
     * @return none
     */
    public void addPartlist(int barcode, int subBarcode, int quanitity) {
        Product subproduct = products.findProduct(subBarcode);
        Product product = products.findProduct(barcode);
        Partlist partlist = new Partlist(subproduct, quanitity);
        product.addPartlist(partlist);
    }
    
    /**
     * creates an instance of Product Item
     * 
     * @param barcode barcode of Product Item to be created
     * @param serialNumber serialNumber of Product Item to be created
     * 
     * @return none
     */
    public void createProductItem(int barcode, String serialNumber)
    {
        Integer bar = (Integer) barcode;
        Product product = products.findProduct(bar);
        ProductItem productItem = new ProductItem(serialNumber);
        products.addProductItem(product, productItem);
    }
    
    /**
     * finds a product
     * 
     * @param barcode barcode of Product to be found
     * 
     * @return product as Product with barcode
     */
    public Product findProduct(int barcode)
    {
        Product product = products.findProduct(barcode);
        return product;
    }
    
    /**
     * deletes a product
     * 
     * @param barcode barcode of Product to be deleted
     * 
     * @return product to be deleted with barcode
     */
    public boolean deleteProduct(int barcode)
    {
        return products.deleteProduct(barcode);
    }
    
    /**
     * lists all products in product container
     * 
     * @param none
     * 
     * @return products as HashMap
     */
    public HashMap<Integer, Product> listAllProducts()
    { 
        return products.listAllProducts();
    }
    
    /**
     * test method with default data for NonComposite Products 
     * 
     * @param none
     * 
     * @return none
     */
    public void testAddNonCompositeProduct()
    {
        NonCompositeProduct nonCompositeProduct = new NonCompositeProduct("Hammer", "God hammer", 10, 5.0, 10.0, 0, 100, 1, "Byggemarked");
        NonCompositeProduct nonCompositeProduct1 = new NonCompositeProduct("Sav", "God Sav", 20, 5.0, 10.0, 50, 100, 1, "Byggemarked");
        NonCompositeProduct nonCompositeProduct2 = new NonCompositeProduct("Træ", "Godt træ", 30, 5.0, 10.0, 0, 100, 1, "Byggemarked");
        NonCompositeProduct nonCompositeProduct3 = new NonCompositeProduct("Bormaskine", "God bormaskine", 40, 5.0, 10.0, 50, 100, 1, "Byggemarked");
        
        int bar = 10;
        int bar1 = 20;
        int bar2 = 30;
        int bar3 = 40;
        
        products.addProduct(bar, nonCompositeProduct);
        products.addProduct(bar1, nonCompositeProduct1);
        products.addProduct(bar2, nonCompositeProduct2);
        products.addProduct(bar3, nonCompositeProduct3);
        
        // Tilføj sammensat produkt
        createCompositeProduct("Køkken", "Flot og moderne køkken", 50, 100000.0, 80000.0, 5);
        addPartlist(50, 10, 3);
        addPartlist(50, 40, 1); 
        addPartlist(50, 20, 4);
        // Slut tilføjelse af sammensat produkt
    }
    
}
